<% /* $Id: monitor_acm.jsp 101 2010-12-26 21:25:55Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="header.jsp" %>

<%
	MonitorInterface monitor = new BasicMonitor(contest.getId());
	monitor.sortACM();
	
	List<ContestUserEntry> users = monitor.getUsers();
	List<ContestProblemEntry> problems = monitor.getProblems();
%>


<h2>Standings [<%= contest.getContestTimeString() %>]</h2>
<!--  <p>Last success: 632:54:07, UzhNU, D6.</p> -->

<table width="100%" class="standings">
	<tr>
		<th class="st_place">Place</th>
		<th class="st_team">Team</th>
<%
	for (ContestProblemEntry problemEntry: problems)
	{
%>
		<th class="st_prob"><a href="<%= Linker.link("contests/problem.jsp?contest_id=" + contest.getId() + "&problem_id=" + problemEntry.getId()) %>"><%= problemEntry.getSid() %></a></th>
<%		
	}
%>
		<th class="st_total">=</th>
		<th class="st_pen">Time</th>
	</tr>


<%
	int c = 0, last_score = -1, last_place = 0;
	long last_time = -1;
	for (ContestUserEntry userEntry: users) if (contest.getShowFullMonitor() || contestUser.isJudge() || userEntry.getUserId().equals(user.getId()))
	{
		ContestUserScoreEntry userScoreEntry = monitor.getUserScore(userEntry.getUserId());
		if (!userEntry.isScored())
			continue;
		boolean fOK = false; 
		if (userEntry.getRole().startsWith("user"))
		{
			c++;
			if (userScoreEntry.getTotalScore() != last_score || userScoreEntry.getTotalTime() != last_time)
				last_place = c;
			last_score = userScoreEntry.getTotalScore();
			last_time = userScoreEntry.getTotalTime();
			fOK = true;
		}
%>


<tr>
	<td class="st_place"><center><%= fOK && last_score > 0 && (contest.getShowFullMonitor() || contestUser.isJudge() || userEntry.getUserId().equals(user.getId())) ? last_place : "*" %></center></td>
	<td class="st_team"><%= StringEscapeUtils.escapeHtml(userEntry.getName())  %></td>
<%
	for (ContestProblemEntry problemEntry: problems)
	{
		ProblemUserScoreEntry score = monitor.getProblemUserScore(problemEntry.getId(), userEntry.getUserId());
		String txt = "-";
		if (score != null && score.getMaxScore() >= 0)
		{
			if (score.getAccepted())
				txt = "<b>" + "+" + (score.getRejectedBeforeAcceptedCount() > 0 ? score.getRejectedBeforeAcceptedCount() : "") + "</b><div class=\"st_time\">" + Formatters.formatContestTime(score.getMaxScoreFirstTime()) + "</div>";
			else
				txt = "-" + score.getRejectedCount() + "<div class=\"st_time\">" + Formatters.formatContestTime(score.getLastSubmittedTime()) + "</div>";
		}
		String color = "white";
		if (score != null)
		{
			color = (score.getAccepted() ? "#ddffdd" : 
							(score.getPendingCount() > 0 ? "#ffffaa" :
								(score.getUniqueRejectedCount() > 0 ? "#ffaaaa" : "white")
							)
						);
		}
%>
	<td class="st_prob" bgcolor="<%= color %>"><a style="text-decoration:none" href="<%= Linker.link("contests/submissions.jsp?contest_id=" + contest.getId() + "&user_id=" + userEntry.getUserId() + "&problem_id=" + problemEntry.getId()) %>"><center><%= txt %></center></a></td>
<%
	}
%>
	<td class="st_total">
		<a style="text-decoration:none" href="<%= Linker.link("contests/submissions.jsp?contest_id=" + contest.getId() + "&user_id=" + userEntry.getUserId() + "&judgement=AC") %>">
			<center><%= userScoreEntry.getUniqueAcceptedCount() %></center>
		</a>
	</td>
	<td class="st_pen"><center><%= userScoreEntry.getTotalTime() %></center> </td>
</tr>
<%
	}
%>
</table>


<%
	Long pageGenerationFinished = new Date().getTime();
%>

<!-- <%= "" + ((pageGenerationFinished - pageGenerationStarted)) + " ms" %>  -->


<%@ include file="footer.jsp" %>
